package com.atguigu.gmall.order.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.order.vo.OrderSplitReps;
import com.atguigu.gmall.order.vo.OrderSubmitVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author lhh
 * @ClassName OrderApiController
 * @date 2022 2022/12/23
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/api/order")
public class OrderApiController {

    @Resource
    OrderBizService orderBizService;

    @Resource
    OrderInfoService orderInfoService;



    @ApiOperation(value = "提交订单")
    @PostMapping("/auth/submitOrder")
    public Result orderSubmit(@RequestParam("tradeNo") String tradeNo,
                              @Valid @RequestBody OrderSubmitVo submitVo){
        Long orderId=orderBizService.orderSubmit(submitVo,tradeNo);
        return Result.ok(orderId+"");
    }

    @ApiOperation(value = "根据库存系统进行拆单")
    @PostMapping("/orderSplit")
    public List<OrderSplitReps> orderSplit(@RequestParam("orderId") Long orderId,
                                           @RequestParam("wareSkuMap") String json){
        List<OrderSplitReps> orderSplits=orderBizService.orderSplit(orderId,json);
        return orderSplits;
    }

    @ApiOperation(value = "查询我的订单")
    @GetMapping("/auth/{page}/{limit}")
    public Result getOrderList(@PathVariable Integer page,@PathVariable Integer limit){
        Page<OrderInfo> orderInfoPage = new Page<>(page,limit);
        orderInfoPage=orderInfoService.pageList(orderInfoPage);
        return Result.ok(orderInfoPage);
    }
}
